//
//  MYShopListClassGoodsCell.m
//  MuYing
//
//  Created by tbb on 2019/7/25.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYShopListClassGoodsCell.h"
#import "MYShopListClassGoodsCollViewCell.h"
#import "MYShopDetailsVC.h"
@interface MYShopListClassGoodsCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic ,strong) UICollectionView *goodsCollView;

@property (nonatomic, strong) UILabel * titleLb;

@property (nonatomic, strong) UIView * bgView;
@end

@implementation MYShopListClassGoodsCell

- (void)setModel:(YQPRecommendSkuModel *)model
{
    _model = model;
    
    self.titleLb.text = kYQLS(model.catalog2Name);
    
    if (!IsArrEmpty(model.skuList)) {
        [self.goodsCollView reloadData];
    }
}

-(UICollectionView *)goodsCollView
{
    if (!_goodsCollView) {
        UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
//                layout.minimumLineSpacing= 12.0f;
//                layout.minimumInteritemSpacing= 12.0f;
        layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
        
        _goodsCollView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 37, self.bgView.width, 209-37) collectionViewLayout:layout];
        _goodsCollView.contentInset = UIEdgeInsetsMake(0, 8, 8, 8);
        _goodsCollView.delegate=self;
        _goodsCollView.dataSource=self;
        _goodsCollView.backgroundColor=[UIColor whiteColor];
        [_goodsCollView setShowsHorizontalScrollIndicator:NO];
        
        _goodsCollView.bounces = NO;
        
        [self.bgView addSubview:_goodsCollView];
        
        [_goodsCollView registerNib:[UINib nibWithNibName:@"MYShopListClassGoodsCollViewCell" bundle:nil] forCellWithReuseIdentifier:@"MYShopListClassGoodsCollViewCell"];
        
    }
    return _goodsCollView;
}

-(UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [[UILabel alloc] init];
        _titleLb.font = kSystemMedium(14);
        _titleLb.textColor = kAPPMainTitleColor;
        _titleLb.text = kYQLS(@"分类");
    }
    return _titleLb;
}

-(UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(12, 0, kScreenWidth-24, 209-12)];
        _bgView.backgroundColor = UIColor.whiteColor;
        
        _bgView.layer.cornerRadius = 12;
        _bgView.clipsToBounds = true;
    }
    return _bgView;
}
#pragma mark -- <UICollectionViewDelegate,UICollectionViewDataSource>
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    YQPRecommendSkuModel *model = self.model;
    return model.skuList.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YQPSkuEntityModel *entityModel = self.model.skuList[indexPath.row];
    MYShopListClassGoodsCollViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MYShopListClassGoodsCollViewCell" forIndexPath:indexPath];
    cell.titleLb.text = entityModel.productName;//@"羊奶粉3段150g";
    cell.priceLb.text = [NSString stringWithFormat:@"HKD%@",entityModel.currentPrice];//@"$600.00";
    cell.originalPriceLb.text = [NSString stringWithFormat:@"HKD%@",entityModel.originalPrice];//@"$670.00";
    [cell.goodsIcon sd_setImageWithURL:kURL(entityModel.defaultImage) placeholderImage:IMAGE_NAMED(@"")];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(112,154+10);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 33.0;
}
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
//    return 12.0;
//}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YQPSkuEntityModel *model = self.model.skuList[indexPath.row];

    MYShopDetailsVC *detailsVC = [[MYShopDetailsVC alloc] init];
    detailsVC.skuId = model.skuId;
    [self.YQViewController.navigationController pushViewController:detailsVC animated:true];
}
#pragma mark -- <UICollectionViewDelegate,UICollectionViewDataSource> end


- (void)layoutSubviews {
    [super layoutSubviews];
    [self.contentView addSubview:self.bgView];
    self.contentView.backgroundColor = HexColor(0xF6F6F6);
    [self.goodsCollView reloadData];
    
    [self.bgView addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8);
        make.left.mas_equalTo(8);
        make.height.mas_equalTo(21);
    }];
}


@end
